using CoreProject.IRepository;
using CoreProject.IService;
using System.Linq.Expressions;

namespace CoreProject.Service
{
    public class BaseService<T> : IBaseService<T> where T : class
    {
        internal readonly IBaseRepository<T> _repository;

        public BaseService(IBaseRepository<T> repository)
        {
            this._repository = repository;
        }

        public async Task<T> GetAsync(Expression<Func<T, bool>> whereLambda)
        {
            return await _repository.GetAsync(whereLambda);
        }

        public async Task<List<T>> GetListAsync<S>(bool isAsc, Expression<Func<T, S>> orderLambda, Expression<Func<T, bool>> whereLambda)
        {
            return await _repository.GetListAsync(isAsc, orderLambda, whereLambda);
        }

        public async Task<(List<T> list, int count)> GetListByPageAsync<S>(int page, int sizie, bool isAsc, Expression<Func<T, S>> orderLambda, Expression<Func<T, bool>> whereLambda)
        {
            return await _repository.GetListByPageAsync(page, sizie, isAsc, orderLambda, whereLambda);
        }


        public async Task<bool> AddAsync(T t)
        {
            return await _repository.AddAsync(t);
        }


        public async Task<bool> UpdateAsync(T t)
        {
            return await _repository.UpdateAsync(t);
        }


        public async Task<bool> DeleteAsync(T t)
        {
            return await _repository.DeleteAsync(t);
        }

        public async Task<bool> DeleteRangeAsync(T[] ts)
        {
            return await _repository.DeleteRangeAsync(ts);
        }
  }
}
